package com.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.order.mapper.ProductCategoryMapper;
import com.order.pojo.ProductCategory;
import com.order.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ProductCategoryServiceImpl extends ServiceImpl<ProductCategoryMapper,ProductCategory> implements ProductCategoryService {

    @Autowired
    ProductCategoryMapper productCategoryMapper;

    @Override
    public PageInfo<ProductCategory> getCategoriesByPage(Integer page, Integer size, ProductCategory productCategory) {
        PageHelper.startPage(page, size);
        QueryWrapper<ProductCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(true, "category_name", productCategory.getCategoryName());
        queryWrapper.eq(true, "category_del", 0);
        List<ProductCategory> categories = productCategoryMapper.selectList(queryWrapper);
        return PageInfo.of(categories);
    }

}
